package com.zhl.algirithm1;

public class Test3 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5,21,37,42,53,64,75,86,97,108,119,130,141,152,163,240,251,262,273,284,295,306};
        System.out.println(Search(arr, 42));
    }


    public static int Search(int[] arr, int target){
        int start = 0;
        int end = arr.length - 1;

        while(start <= end){

            int mid = (start + end) / 2;
            if(arr[mid] < target){
                start = mid+1;
            }else if(arr[mid] > target){
                end = mid - 1;
            }else{
                return mid;
            }
        }
        return -1;  // not found
    }

}
